<?php
namespace app\web\controller;

use app\model\Theme; 

class Clive extends Base
{
    public function Clive()
    {
global $_G, $_P;
$themeid = $_P['themeid'];
$op = $_P['op'];
//load_func('tpl');
//loadload_func('communication');

if ($op == "list") {
    $r = Theme::getConfig($themeid);
    if(empty($r)){
        self::saveLiveConfig(-1,0,0,"",$_G,$r);
    }
    $r = $r['livedata'];
    $users = db_getall(t_fans, array('themeid' => $themeid, "sublive" => 1), array("username", "nickname", "openid", "avatar"));
    include $this->template("web/clive");
} else if ($op == "update") {
    $lid =  $_P["lid"];
    $time = $_P["stime"];
    $lname = $_P['lname'];
    $stime = $time['start'];//strtotime($time);
    $relive = $_P['relive'];
    $r = self::saveLiveConfig($lid,$stime,$relive,$lname,$_G,Theme::getConfig($themeid));
    return_tips($r ? "更新成功" : "更新失败", createWebUrl("clive", array("themeid" => $themeid, "op" => "list")));
} else if ($op == "notify") {
    $r = db_update(t_fans,array('msgstatus'=>0), array("themeid" => $themeid, "sublive" => "1"));
    $c = Theme::getConfig($themeid);
    $c ['livedata']['sendnotify'] = 1;
    Theme::setConfig($c,$themeid,$_G['mpid']);
}
}
function saveLiveConfig($_liveId,$_liveTime,$relive,$lname,$_G,&$_r){
    $_r['livedata'] = array("liveid"=>$_liveId,"livetime" => $_liveTime,"livestatus"=>102,"sendnotify"=>0,'relive'=>$relive,'lname'=>$lname);
    return Theme::setConfig($_r,"1",$_G['mpid']);
}
}